import FMJava from "../../../../Common/FMJava";
import { mgrs } from "../../../system/OverallSystem ";
import { authorizeParams, getUserInfoParams, loadParams, loginParams, MiniGameApiBase, ModalParams, recordedGameScreenParams, toastParams } from "../miniGameBase/miniGameApiBase";


export default class H5Api extends MiniGameApiBase {





    protected m_AppId: string;
    protected m_Secret: string;

    protected m_VideoAdIdIndex: number;
    protected m_VideoAdIdList: string[];

    protected m_BannerAdIdIndex: number = 0;
    protected m_BannerAdId: string[];

    protected m_InsertAdIdIndex: number;
    protected m_InsertAdId: string[];

    protected m_videoAd: unknown;
    protected m_BannerAd: unknown;

    validAppId(): void {
        console.log("h5-api-validAppId");
        console.log("isNative"+cc.sys.isNative)
    }

    ready(): void {
        console.log("h5-api-ready");
    }

    getUserInfo(params: getUserInfoParams): void {
        console.log("h5-api-getUserInfo");
    }

    showToast(params: toastParams): void {
        console.log("h5-api-showToast");
    }

    showLoading(params: loadParams): void {
        console.log("h5-api-showLoading");
    }

    hideLoading(): void {
        console.log("h5-api-hideLoading");
    }

    showModal(params: ModalParams): void {
        console.log("h5-api-showModal");
    }

    authorize(params: authorizeParams): void {
        console.log("h5-api-authorize");
    }

    login(params: loginParams): void {
        console.log("h5-api-login");
    }



    loadAndShowVideoAd(successCB: () => void, errorCB: (error: any) => void, completeCB?: () => void, reportAnalyticsExplain?: string): void {
        if (cc.sys.platform == cc.sys.ANDROID) {
            console.log("android-sdk-loadAndShowVideoAd");
            this.showRewardedVideoAd((isok: boolean) => {
                if (isok) {
                    console.log("播放激励视频完成");
                    setTimeout(() => {
                        successCB();
                    }, 60);
                    
                } else {
                    console.log("播放激励视频失败");
                    errorCB('视频中途退出');
                }
            }, () => {
                console.log("播放激励视频失败");
                completeCB && completeCB();
            })
        }else{
            console.log("h5-api-loadAndShowVideoAd");
            setTimeout(() => {
                successCB();
            }, 60);
            completeCB && completeCB();
        }

        
    }

    /**
     * 播放激励视频
     * @param success 
     * @param fail 
     */
    public showRewardedVideoAd(success: Function, fail: Function) {
        console.log("播放激励视频");
        FMJava.showRewardedVideoAd(success, fail);
    }

    FullScreenVideoAd(successCB: () => void, errorCB: (error: any) => void, completeCB?: () => void, reportAnalyticsExplain?: string) {
        if (cc.sys.platform == cc.sys.ANDROID) {
            FMJava.show_FullScreenVideo((isok: boolean) => {
                if (isok) {
                    console.log("播放激励视频完成");
                    successCB();
                } else {
                    console.log("播放激励视频失败");
                    errorCB('视频中途退出');
                }
            }, () => {
                console.log("播放激励视频失败");
                completeCB && completeCB();
            });
        }
    }

    showInsertAd(onAdClose: () => void, onFailed: () => void): void {
        console.log("h5-api-showInsertAd");
        onAdClose();
    }

    

    showBannerAD(node: cc.Node, successCB?: () => void, errorCB?: (error: any) => void, onCloseCB?: () => void,
        setBannerPos?: ({ screenWidth, screenHeight }: { screenWidth: any; screenHeight: any; }) => cc.Vec2): void {
        console.log("h5-api-showBannerAD");
    }
    hideBanner(): void {
        console.log("h5-api-hideBanner");
    }


    recordedGameScreenStart(params: recordedGameScreenParams, onStart?: (res: any) => void): void {
        console.log("h5-api-recordedGameScreenStart");
        onStart && onStart(null);
    }
    recordedGameScreenStop() {
        console.log("h5-api-recordedGameScreenStop");
        return true;
    }
    shareRecordedGameScreen(successCb?: () => void, failCb?: (e?: any) => void): void {
        console.log("h5-api-shareRecordedGameScreen");
        successCb && successCb();
    }
    isHaveRecordedGameScreen(): boolean {
        return true;
    }

    reportAnalytics(name,data){
        
    }

    vibrateShort(type = 'heavy') {

        if (!mgrs().soundMgr.isVibration) return
        cc.log('震动' + type)
       
    }

    shareAppMessage(){
        
    }
}